﻿using Asp.Versioning;
using FlyingEye.ComServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace FlyingEye.Controllers
{
    [Route("api/device-ops-service/v{version:apiVersion}/user-configurations")]
    [ApiVersion("1.0")]
    [ControllerName("ComeUserNotificationConfiguration")]
    [Authorize]
    public class ComeUserNotificationConfigurationController : DefaultController
    {
        private readonly ComeUserNotificationConfigurationService _comeUserNotificationConfigurationService;

        public ComeUserNotificationConfigurationController(ComeUserNotificationConfigurationService comeUserNotificationConfigurationService)
        {
            _comeUserNotificationConfigurationService = comeUserNotificationConfigurationService;
        }

        [HttpGet("{id}", Name = "GetByComeUserNotificationConfigurationId")]
        public async Task<ActionResult<ComeUserNotificationConfigurationResponse>> GetAsync(Guid id)
        {
            return await GetInvokeAsync(async () =>
            {
                return await _comeUserNotificationConfigurationService.GetAsync(id);
            });
        }

        [HttpPost]
        public async Task<ActionResult<ComeUserNotificationConfigurationResponse>> InsertAsync([FromBody] CreateComeUserNotificationConfigurationRequest user)
        {
            return await InsertInvokeAsync(async () =>
            {
                return await _comeUserNotificationConfigurationService.InsertAsync(user);
            }, "GetByComeUserNotificationConfigurationId", (result) => new { id = result.Id });
        }

        [HttpDelete("{id}")]
        public async Task<NoContentResult> DeleteAsync(Guid id)
        {
            return await DeleteInvokeAsync(async () =>
            {
                await _comeUserNotificationConfigurationService.DeleteAsync(id);
            });
        }
    }
}
